import userService from '../services/UserService/index.js';

class UserController {
  // 获取所有菜单
  async getMenu(req, res) {
    try {
      const menuData = await userService.getAllMenu();
      
      if (!menuData) {
        return res.status(404).json({
          code: 404,
          message: '菜单数据未找到'
        });
      }
      
      res.json({
        code: 200,
        message: '获取菜单成功',
        data: menuData
      });
    } catch (error) {
      res.status(500).json({
        code: 500,
        message: '服务器错误',
        error: error.message
      });
    }
  }
  
  // 根据ID获取菜单
  async getMenuById(req, res) {
    try {
      const { id } = req.params;
      const menuItem = await userService.getMenuById(id);
      
      if (!menuItem) {
        return res.status(404).json({
          code: 404,
          message: `未找到ID为${id}的菜单`
        });
      }
      
      res.json({
        code: 200,
        message: '获取菜单成功',
        data: menuItem
      });
    } catch (error) {
      res.status(500).json({
        code: 500,
        message: '服务器错误',
        error: error.message
      });
    }
  }
}

export default new UserController();
    